const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  // 开发服务器配置
  devServer: {
    port: 8080,
    host: 'localhost',
    // 支持 History 模式路由
    historyApiFallback: true,
    // 热重载
    hot: true,
    // 自动打开浏览器
    open: false,
    // 客户端配置
    client: {
      overlay: {
        errors: true,
        warnings: false,
        runtimeErrors: (error) => {
          const ignoreErrors = [
            'ResizeObserver loop limit exceeded',
            'ResizeObserver loop completed with undelivered notifications'
          ]
          return !ignoreErrors.some(ignoreError => 
            error.message && error.message.includes(ignoreError)
          )
        }
      }
    }
  },
  // 构建配置
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  // 生产环境不生成 source map
  productionSourceMap: false,
  // CSS 配置
  css: {
    // 是否开启 CSS source map
    sourceMap: false
  },
  // 配置 webpack
  configureWebpack: {
    resolve: {
      fallback: {
        "path": false,
        "fs": false
      }
    }
  },
  chainWebpack: config => {
    config.plugin('define').tap(definitions => {
      Object.assign(definitions[0], {
        __VUE_OPTIONS_API__: 'true',
        __VUE_PROD_DEVTOOLS__: 'false',
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
      })
      return definitions
    })
  }
})
